<script>
import { mapGetters, mapActions, mapMutations } from "vuex"
export default {
    async onLaunch(options) {
        console.log(options)
        const { aid = "", invite_code = "", code, state } = options.query
        const token = uni.getStorageSync("token")
        if (code && state) {
            try {
                if (invite_code) {
                    return uni.navigateTo({ url: `/pages/login/register?invite_code=${invite_code}` })
                }
                await this.userLogin({ code, type: 1, method: "userLogin2" })
                uni.reLaunch({ url: "/pages/index" })
            } catch {
                if (token) {
                    uni.reLaunch({ url: "/pages/index" })
                }
            }
        } else {
            if (aid) {
                return uni.reLaunch({ url: `/pages/control/index?aid=${aid}` })
            }
            const REDIRECT_URI = `${process.env.VUE_APP_H5_URL}/control/?invite_code=${invite_code}`
            const { url } = await this.$api.getWechatUrl({ url: REDIRECT_URI, scope: 1 })
            window.location.replace(url)
        }
        console.log("App Launch")
    },
    onShow: function () {
        console.log("App Show")
    },
    onHide: function () {
        console.log("App Hide")
    },
    methods: {
        ...mapActions(["userLogin"])
    }
}
</script>

<style lang="scss" src="./static/scss/main.scss" />
